<template>
  <a-select
    style="width:100%;"
    showSearch
    allowClear
    :disabled="disabled"
    :filterOption="filterOption"
    :placeholder="placeholder"
    @change="handleChange"
    :value="seletedValue"
  >
    <a-select-option
      v-for="(item) in lists"
      :key="item.pid">
      <!-- {{item.chanPingdm}} -->
      {{item.orgName}}({{ item.orgCode}})
    </a-select-option>
  </a-select>
</template>

<script>
import { getByConditions } from './notification'

export default {
  name: 'notificationSelect',
  props: {
    placeholder: {
      default: '选择发票抬头',
      required: false,
      type: String
    },
    disabled: {
      default: false,
      required: false,
      type: Boolean
    },
    value: {
      default: '',
      required: false,
      type: String
    }
  },
  data () {
    return {
      lists: [],
      seletedValue: (this.value == '' || this.value === null) ? undefined : this.value
    }
  },
  computed: {
    placeholderShow() {
      return this.placeholder
    }
  },
  created () {
    this.initDictData()
  },
  methods: {
    initDictData () {
      const pagination = {
        pageSize: 1000000,
        current: 1
      }
      const headers = {
        authOption: '1'
      }
      getByConditions({}, pagination, headers).then(r => {
        if (r && r && r.code === 'C1' && r.data) {
          console.log(r.data);
          this.lists = r.data
        }
      })
    },
    filterOption (input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      )
    },
    handleChange (val) {
      console.log(val,this.lists);
      // if (val !== undefined) {
        let record=this.lists.find(item=>{
          return item.pid==val
        })
        console.log(record);
        this.$emit('change', val,record)
      // }
      // this.$emit('dataChanged', val)
    }
  },
  watch: {
    value: function () {
      this.seletedValue = (this.value == '' || this.value === null) ? undefined : this.value
    }
  }
}
</script>
